package com.dayu.rabbitmq.work;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.dayu.rabbitmq.util.MQUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * @author dayu
 * @date 2019/02/20
 * @Describe worker queues 轮询，每个消费者处理相同
 * 
 */
public class Send {
    private static String QUEUE_NAME = "worker queues";

    //              |--C1
    // * 工作队列 P----|
    //              |--C2

    public static void main(String[] args) throws IOException, TimeoutException {
        // 获取连接
        Connection connection = MQUtil.getConnection();
        // 创建通道
        Channel channel = connection.createChannel();

        // 发送
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);

        for (int i = 0; i < 50; i++) {
            String message = "hello " + i;
            System.out.println(" QW SEND :"+message);
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
        }

        channel.close();
        connection.close();

    }
}
